package gui;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JComboBox;
import java.awt.SystemColor;
import java.util.ArrayList;

import javax.swing.SwingConstants;

import common.ChatIF;

/**
 * 
 * @author Chen Parodi
 * This GUI Class services the Assessors,
 * With it they have access to the all the requests that need assessment.
 *  *
 */
public class AssessorPanel extends JPanel implements ChatIF{
	String pid;
	String currentStatus;
	SignificationAssessment significtionAssessment;
	SetAssessDuration setAssessDuration;
	AcademicFrame frame;
	AssessorPanel assessor;
	MainWindow mainWindow;
	ArrayList<Object> listofAssessorRequests;
	
	public AssessorPanel(AcademicFrame frame,MainWindow mainWindow,String pid) {
		super();
		setBackground(SystemColor.control);
		this.pid=pid;
		this.frame=frame;
		this.mainWindow=mainWindow;
		this.assessor=this;
		
		
		
		initialize();
		
	
		
	}
	
	private void initialize() {
		setLayout(null);		
		
	//	this.setAssessDuration= new SetAssessDuration(frame,assessor,pid);
		JLabel lblAssessor = new JLabel("Assessor");
		lblAssessor.setHorizontalAlignment(SwingConstants.LEFT);
		lblAssessor.setForeground(Color.BLACK);
		lblAssessor.setFont(new Font("Tahoma", Font.BOLD, 32));
		lblAssessor.setBounds(30, 11, 292, 56);
		add(lblAssessor);
		
		JButton btnSignificationAssessment = new JButton("Signification Assessment");
		btnSignificationAssessment.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				ArrayList<Object> changeStatus = new ArrayList<Object>();
				changeStatus.add("changeStatus");
				AcademicFrame.myclient.sendMessageToServer(changeStatus);
					significtionAssessment= new SignificationAssessment(frame, assessor,pid);					
					listofAssessorRequests = new ArrayList<Object>();
					listofAssessorRequests.add("getlistOfExRequests");
					listofAssessorRequests.add(pid);
					listofAssessorRequests.add("4");
					listofAssessorRequests.add("Aid");
					listofAssessorRequests.add("request");
					
					AcademicFrame.myclient.sendMessageToServer(listofAssessorRequests); // get list of systems
					
					frame.setContentPane(significtionAssessment);
					frame.setSize(500, 500);

			}
		});
		btnSignificationAssessment.setBounds(30, 134, 210, 23);
		add(btnSignificationAssessment);
		
		JButton btnSetAssessDuration = new JButton("Set Assess Duration");
		btnSetAssessDuration.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setAssessDuration= new SetAssessDuration(frame,assessor,pid);
				listofAssessorRequests = new ArrayList<Object>();
				listofAssessorRequests.add("getlistOfExRequests");
				listofAssessorRequests.add(pid);
				listofAssessorRequests.add("2");
				listofAssessorRequests.add("Aid");
				listofAssessorRequests.add("request");
				
				AcademicFrame.myclient.sendMessageToServer(listofAssessorRequests); // get list of systems
				
				frame.setContentPane(setAssessDuration);
				frame.setSize(500, 500);
			}
		});
		btnSetAssessDuration.setBounds(30, 87, 210, 23);
		add(btnSetAssessDuration);
		
		JButton btnBack = new JButton("Back");
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.setSize(500, 500);
				frame.setContentPane(mainWindow);
			}
		});
		btnBack.setBounds(30, 177, 210, 23);
		add(btnBack);
		
		JLabel label = new JLabel("___________________________");
		label.setBounds(30, 42, 387, 14);
		add(label);
	}
	public void display(Object message){
		ArrayList<String> replyFromServer = (ArrayList<String>)message; 	
	
		if( ((String)(replyFromServer.get(0))).equalsIgnoreCase("changeStatus")){
			if ( !((String)(replyFromServer.get(1))).equalsIgnoreCase("statusSet") )
			{
			
				(new Dialog ("An Error occured while writing to the database.")).setVisible(true);
				
				frame.setContentPane(mainWindow);	
				frame.setSize(500, 500);
			}
		}
	}
	
	
}
